
const g = require('../utils/global');

cc.Class({
    extends: cc.Component,

    properties: {
    },

    // 发射子弹
    fire(startX, startY, controller, flag) {
        this.node.x = startX;
        this.node.y = startY;
        const move = cc.moveBy(g.AnimTime.heroBullet, cc.v2(0, g.SKY_HEIGHT*flag));
        const cb = cc.callFunc(function (target) {
            target.destroy();
        }, this);
        this.node.runAction(cc.sequence(move, cb));
        this.controller = controller;
    },

    // 碰撞发生
    onCollisionEnter(other, self) {
        if (other.tag === g.CollisionTag.enemy) {
            this.controller.fireBullet(this);
        }
        cc.log(`other = ${other.tag}, self = ${self.tag}`);
    },
});
